package com.imooc.homework;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/add")
public class work1_add extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public work1_add() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//从html页面表单中获取提交的数据
		String number = request.getParameter("number");
		int n = Integer.parseInt(number);
		int sum = 0;
		for(int i = 1;i <= n;i++) {
		sum = sum + i;
		}
		String num =Integer.toString(sum);

		request.setAttribute("sum", num);
		
		request.getRequestDispatcher("/result").forward(request, response);
	}

}
